//
//  ByCellFriendsAndRelatives.m
//  chequanbao_ios
//
//  Created by mc on 2017/11/22.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellFriendsAndRelatives.h"

@implementation ByCellFriendsAndRelatives
{
    UIView      *_bgView;
    UIImageView *_iconImg;
    UILabel     *_nameLabel;
}

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellFriendsAndRelatives";
    ByCellFriendsAndRelatives *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH - 20, 50)];
    [self addSubview:_bgView];
    _bgView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.25];
    _bgView.layer.cornerRadius = 4.0;
    
    _iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
    _iconImg.layer.cornerRadius = 30 / 2;
    _iconImg.layer.masksToBounds = YES;
    [_bgView addSubview:_iconImg];
    
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImg.right + 15, 10, SCREEN_WIDTH - 20 - _iconImg.right - 15, 30)];
    _nameLabel.font = FONT(16);
    _nameLabel.textColor = [UIColor whiteColor];
    [_bgView addSubview:_nameLabel];
}

- (void)setModel:(ByModelFriendAndRelative *)model{
    _nameLabel.text = model.nickname;
    [_iconImg setImageWithURL:[NSURL URLWithString:BOYE_PICTURE_VIEW_URL(model.head)] placeholderImage:DEFAULT_HEAD completed:nil];
}
@end
